@extends('admin.layout.layout', ['row' => @$page])

@section('contain')


    <div class="portlet">
        <div class="portlet-title">
            <div class="caption">
                <x-portlet-breadcrumb :page="$page"></x-portlet-breadcrumb>
            </div>
            <div class="actions">
                <div class="item">
                    @if (!empty($user_type) && $user_type == 2 && 0)
                        <a href="/admin/warranty_delete/add" class="btn btn-primary">添加</a>
                    @endif
                </div>
            </div>
        </div>

        <div class="filter-wrapper">
            <form action="/{{ request()->path() }}/" class="form-inline filter-form">
                <div class=" input-group mb-3 custom-control-inline">
                    <input type="text" class="form-control s-input" name="value" value="{{ request()->input('value') }}" placeholder="质保Id">
                </div>
                @if (!empty($distributions))
                    <div class=" input-group mb-3 custom-control-inline">
                        <select name="distribution_id" class="form-control distribution_id">
                            <option value="">{{ ts('select') }}</option>
                            @foreach($distributions as $item)
                                <option value="{{ $item->id }}" {{ request()->input('distribution_id') == $item->id ? 'selected' : '' }}>{{ $item->abbr }}</option>
                            @endforeach
                        </select>
                    </div>
                @endif
                <x-flatpickr-date-range></x-flatpickr-date-range>
                <div class="mb-3">
                    <button class="btn btn-primary">{{ ts('SEARCH') }}</button>
                    <a href="/{{ request()->path() }}/" class="btn btn-warning">{{ ts('RESET') }}</a>
                </div>

            </form>
        </div>

        <div>
            <table class="table text-nowrap bt-table table-bordered table-hover">
                <thead>
                <tr class="order_column">
                    <th style="width: 75px;">{{ ts('sequence') }}</th>
                    <th style="width: 100px;" data-field="warranty_id" class="sortable {{ setOrderClass('warranty_id') }}">{{ ts('warrantyid') }}</th>
                    <th style="width: 400px;">删除原因</th>
                    <th style="width: 100px;">申请省代</th>
                    <th style="width: 100px;">申请账号</th>
                    <th style="width: 100px;">申请时间</th>
                </tr>
                </thead>
                <tbody>
                @foreach($data as $k => $v)
                    <tr class="item-list">
                        <td class="text-center">{{ @$data->firstItem()+$k }}</td>
                        <td>
                            <div class="truncated-3">{{ @$v->warranty_id }}</div>
                        </td>
                        <td>
                            {{ $v->delete_reason ?? '' }}
                        </td>
                        <td>{{ $v->abbr }}</td>
                        <td>{{ $v->unique_id }}</td>
                        <td>{{ $v->created_time }}</td>
                    </tr>
                @endforeach
                </tbody>
            </table>

            <div class="row my-3">
                <div class="col">
                    {{ $data->appends(request()->input())->links() }}
                </div>
            </div>
        </div>
    </div>


@endsection

@section('script')
    <script>
        @if (!empty($distributions))
            $(".distribution_id").select2();
        @endif
        function delete_request(id) {
            request.delete('/admin/warranty_delete/', {
                id: id
            })
                .then(function (d) {
                    console.log(d);
                    var msg = (d.data && data.msg) || d.msg || '发送成功';
                    sw3(msg)
                })
                .catch(function (d) {
                    console.log('flkadsflkasflksafsfs');
                    console.log(d);
                    var data = d.data;
                    var msg = (d.data && data.msg) || d.msg || '发送失败';
                    sw3(msg, 'error')
                })

            console.log(id)
        }
    </script>
@endsection
